<?php


namespace App\Http\Controllers\Admin\Log;


use App\Http\Controllers\Admin\BaseController;
use App\Repositories\Log\ImportRepository;
use App\Utils\Output;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;

class ImportController extends BaseController
{
    public function __construct()
    {
        $this->set('log/import');
    }

    function index($type, ImportRepository $rep, Request $request)
    {
        $search = $request->all();
        $search['type'] = $type;
        if ($request->ajax()) {
            return $rep->adminPager($search);
        }
        return $this->view('index');
    }

    function down($type, $id, ImportRepository $rep)
    {
        $entity = $rep->get($id);
        if ($type == 1) {
            return Response::download(Storage::path($entity->import_path), $entity->file_name);
        } else {
            return Response::download(Storage::path($entity->error_path), '错误数据.xlsx');
        }
    }
}
